Skip to content

London | 26-ITP-January | Mouawia Elkhalifa | Sprint 2 | Data Groups#1077

Open
MouawiaElkhalifa wants to merge 1 commit intoCodeYourFuture:mainfrom
MouawiaElkhalifa:sprint-2
Open

London | 26-ITP-January | Mouawia Elkhalifa | Sprint 2 | Data Groups#1077
MouawiaElkhalifa wants to merge 1 commit intoCodeYourFuture:mainfrom
MouawiaElkhalifa:sprint-2

Conversation

@MouawiaElkhalifa
Copy link

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implemented all Sprint 2 exercises including:

  • Debug tasks (address, author, recipe)
  • Implement tasks (contains, lookup, querystring, tally)
  • Interpret task (invert)

All functions were tested and verified to meet the expected behavior. Edge cases such as invalid input and duplicate values were handled where required.

@MouawiaElkhalifa MouawiaElkhalifa added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 23, 2026
return false;
}

return prop in obj;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the following two approaches for determining if an object contains a property:

  let obj = {}, propertyName = "toString";
  console.log( propertyName in obj );                // true
  console.log( Object.hasOwn(obj, propertyName) );   // false

Which of these approaches suits your needs better?
For more info, you can look up JS "in" operator vs Object.hasOwn.

Comment on lines +44 to +46
test("return false when paramters invaliud ", () =>{
expect(contains([], "a")).toEqual(false)
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does not yet confirm that the function correctly returns false when the first argument is an array.
This is because contains([], "a") could also return false simply because "a" is not a key of the array.

Arrays are objects, with their indices acting as keys. A proper test should use a non-empty array along with a valid
key to ensure the function returns false specifically because the input is an array, not because the key is missing.

const [key, value] = pair.split("=");
queryParams[key] = value;
const [key, ...valueParts] = pair.split("=");
queryParams[key] = valueParts.join("=");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: (No change required)

  • In real query string, both key and value are percent-encoded or URL encoded in the URL.
    For example, the string "5%" is encoded as "5%25". So to get the actual value of "5%25"
    (whether it is a key or value in the query string), we need to call a function to decode it.

  • You can also explore the URLSearchParams API.

Comment on lines +12 to +21
const result = {};

// count items
for (const item of arr) {
if (result[item] === undefined) {
result[item] = 1;
} else {
result[item] = result[item] + 1;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the following function call returns the value you expect?

tally(["toString", "toString"]);

Suggestion: Look up an approach to create an empty object with no inherited properties.

Comment on lines +12 to +18
if (invertedObj[value] === undefined) {
invertedObj[value] = key;
} else if (Array.isArray(invertedObj[value])) {
invertedObj[value].push(key);
} else {
invertedObj[value] = [invertedObj[value], key];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job in recognising the possibility of collision and taking an extra step to address it.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants